/** \file ChaikinOscillator_t.cc 
 * Test definitions for the ChaikinOscillator function
 *
 * (C) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: ChaikinOscillator_t.cc 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */


#include "ChaikinOscillator.hpp"
#include <vector>
#include <list>
#include "Stock.hpp"
#include "SecurityAdaptor.hpp"
#include "TestHarness.hh"

using namespace std;
using namespace TC;

namespace {

  const unsigned DataSize = 22;

  const double data_hi[DataSize] = {
    8.625, 8.875, 9.375, 10.125, 9.375, 10.125, 10.000,
    9.750, 9.500, 9.625, 10.000, 9.750, 9.125, 9.250,
    9.375, 9.375, 9.375, 8.625,  8.625, 8.625, 8.375,
    8.750 };

  const double data_lo[DataSize] = {
    8.250, 8.375, 8.375, 8.750, 8.750, 9.250,
    9.125, 9.375, 9.000, 8.875, 9.375, 8.750,
    8.750, 9.125, 9.250, 9.125, 8.625, 8.250,
    8.250, 7.875, 7.625, 8.250 }; 

  const double data_cls[DataSize] = {
    8.625, 8.375, 9.375, 8.750, 9.375, 9.875, 9.375,
    9.625, 9.125, 9.250, 9.750, 8.875, 8.875, 9.125,
    9.375, 9.250, 8.625, 8.500, 8.500, 7.875, 8.375,
    8.625 };

  const long data_vol[DataSize] = {
    19194, 10768, 20032, 55218, 13172, 22245, 15987, 9646, 
    10848, 14470, 14973, 15799, 16860, 6568, 8312, 5573, 
    11480, 6366, 8394, 12616, 12287, 12113 }; 


  const double data_expect[DataSize] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0,
    -7540, -5615, -8087, -10151, -12163, -9235, -7198,
    -9363, -8722, -6777, -9379, -5682, -1725 };



}

TEST(ChaikinOscillatorTest, Base)
{
     StockDef s;
     list<StockDef> stocks;
     vector<double> result;
     
     for(unsigned i=0; i<DataSize; ++i) {
       s.setHi(static_cast<StockDef::Price_t>(data_hi[i]));
       s.setLo(static_cast<StockDef::Price_t>(data_lo[i]));
       s.setCls(static_cast<StockDef::Price_t>(data_cls[i]));
       s.setVol(static_cast<StockDef::Volume_t>(data_vol[i]));
       stocks.push_back(s);
     }

     ChaikinOscillator(stocks.begin(), stocks.end(), 
		      back_inserter(result),
		      SecurityAdaptor<StockDef>());

     TC_TEST(result.size()==DataSize);
     PrintElements(result, "ChaikinOscillator");

     for(unsigned i=0; i<DataSize; ++i)
       if(data_expect[i] > 0)
         TC_TESTFP(data_expect[i], result[i]);


}



